package  
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import me.nerik.air.AppSettings;
	/**
	 * ...
	 * @author 
	 */
	public class Params extends EventDispatcher
	{
		
		public static const LOADED:String = "loaded";
		
		private static var _instance:Params = new Params();
		
		public function Params() 
		{
			if (_instance) throw new Error( "Singleton and can only be accessed through Singleton.getInstance()" );
		}

		public static function get instance():Params 
		{
			return _instance;
		}
		
		
		public var excludeTablesStr:String;
		public var outputFile:String;
		
		

		public function initialize():void  
		{
			AppSettings.instance.addEventListener(AppSettings.READY, load);
			AppSettings.instance.initialize();
		}
		
		
		private function load(e:Event):void
		{
			excludeTablesStr = AppSettings.instance.data.excludeTables;
			outputFile = AppSettings.instance.data.outputFile;
			
			dispatchEvent(new Event(LOADED));
		}
		
		public function save():void
		{
			AppSettings.instance.data.excludeTables = excludeTablesStr;
			
			if (outputFile)
			{
				AppSettings.instance.data.outputFile = outputFile;
			}
			
			AppSettings.instance.saveXml();
		}
		
		
		
		
		/*
		private function loadParams(e:Event):void
		{
			if (AppSettings.instance.data.excludeTables != undefined) 
			{
				excludeTablesStr = ui.excludeTablesInput.text = AppSettings.instance.data.excludeTables;
			}
			else
			{
				excludeTablesStr = ui.excludeTablesInput.text = "class, class_in_school, school, session, settings, settings_for_student, student, student_in_class, student_in_session, targetword_by_student, teacher, teacher_in_school, theme_for_class, theme_for_student";
			}
			
			if (AppSettings.instance.data.outputFile != undefined)
			{
				trace("Main::loadParams -" + AppSettings.instance.data.outputFile + "-");
				outputFile = new File(AppSettings.instance.data.outputFile);
				ui.outputBrowseTf.text = outputFile.nativePath;
			}
		}
		
		private function saveParams():void
		{
			AppSettings.instance.data.excludeTables = excludeTablesStr = ui.excludeTablesInput.text;
			excludeTables = excludeTablesStr.replace(/\s/gis, "").split(/,|;/);
			
			if (outputFile)
			{
				AppSettings.instance.data.outputFile = outputFile.nativePath;
			}
			
			AppSettings.instance.saveXml();
		}
		*/
				
		
	}

}